package cn.yunyichina.provider.base.service.impl;

import java.util.List;
import java.util.Map;

import cn.yunyichina.provider.base.dao.OrgSettingDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yunyichina.provider.base.dao.BranchHospitalDao;
import cn.yunyichina.provider.base.dao.OrgDao;
import cn.yunyichina.provider.base.entity.BranchHospital;
import cn.yunyichina.provider.iface.entity.base.Org;
import cn.yunyichina.provider.iface.entity.base.OrgSetting;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.utils.convert.JsonUtils;

/**
 * 分院接口类
 *
 * @author zhangkewen
 */
@Service("branchhospitalServiceImpl")
public class BranchhospitalServiceImpl {

    @Autowired
    private BranchHospitalDao branchHospitalDao;
    @Autowired
    private OrgDao orgDao;
    @Autowired
    private OrgSettingDao orgSettingDao;

//    /**
//     * yyt.base.branchhospital.list 获取医院分院列表
//     *
//     * @param data
//     * @param sessionid
//     * @return
//     */
//    public Response listBranchhospital(String data, String sessionid) {
//
//        Response response = new Response();
//
//        Map map = JsonUtils.parseObject(data, Map.class);
//        String branchCode = (String) map.get("branch_code");
//        String hospitalCode = (String) map.get("hospital_code");
//
//        BranchHospital wheres = new BranchHospital();
//        wheres.setCode(branchCode);
//        wheres.setHospitalCode(hospitalCode);
//        List<BranchHospital> branchHospitals = branchHospitalDao.selectByHospitalCode(wheres);
//
//        response.setResultCodeAndMessage("0", "查询成功!");
//        response.setResult(JsonUtils.toJsonString(branchHospitals));
//        return response;
//    }

    /**
     * yyt.base.branchhospital.org.list
     */
    public Response listBranchhospitalOrg(String data){
        Response response = new Response();

        Map map = JsonUtils.parseObject(data, Map.class);
        String orgCode = (String) map.get("org_code");

        Org where = new Org();
        where.setOrgCode(orgCode);
        List<Org> orgs = orgDao.select(where);

        response.setResultCodeAndMessage("0", "查询成功!");
        response.setResult(JsonUtils.toJsonString(orgs));
        return response;
    }

    /**
     * yyt.base.branchhospital.setting.list
     */
    public Response listBranchhospitalSetting(String data){
        Response response = new Response();

        Map map = JsonUtils.parseObject(data, Map.class);
        String hisCode = (String) map.get("his_code");
        String orgId = (String) map.get("org_id");

        OrgSetting where = new OrgSetting();
        where.setHisCode(hisCode);
        where.setOrgId(orgId);
        List<OrgSetting> list = orgSettingDao.select();

        response.setResultCodeAndMessage("0", "查询成功!");
        response.setResult(JsonUtils.toJsonString(list));
        return response;
    }
}
